﻿using System;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;
using RLI = RGoodSW.Logger.Interfaces;

namespace CodeCamp
{
    public class Bootstrapper
    {
        public static void Initialize()
        {
            SetAutofacContainer();
        }
        private static void SetAutofacContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            // or
            //builder.RegisterControllers(Assembly.GetExecutingAssembly());

            //builder.RegisterType<xxx.LoggerService.Logger>().As<xxx.ILogger>().SingleInstance();

            builder.RegisterType<CodeCamp.Infrastructure.DefaultValueProvider>()
                .As<CodeCamp.Infrastructure.IDefaultValueProvider>().SingleInstance();

            builder.RegisterType<RGoodSW.Logger.WebAppLogServices.Logging.log4netLogger>()
                .As<RLI.ILoggerExtended>().SingleInstance();

            IContainer container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
    }
}